package it.uniroma2.structure;

public class Main_Sequence_Control extends Sequence_Control{
	
	private Receive receive; 
	private Reply reply;
	
	public Main_Sequence_Control(){
		this.receive = new Receive();
		this.reply = new Reply();
		this.receive.setOperation("process");
		this.reply.setOperation("process");
		this.receive.setCreateInstance(true);
		setOrderId("1");
	}
	
	public Main_Sequence_Control(Receive receive, Reply reply){
		this.receive = receive;
		this.reply = reply;
	}
	
	public Main_Sequence_Control(String name) {
		this();
		this.name = name;		
	}
	
	public void setVariableReceive(Variable varIn){
		this.receive.setVariable(varIn);
	}

	public void setVariableReply(Variable varOut){
		this.reply.setVariable(varOut);
	}
	
	
	public Parameter getParameterIn(){
		return this.receive.getParameterInput();
	}

	public Parameter getParameterOut(){
		return this.reply.getParameterResult();
	}
//-------	Set PartnerLink of Recieve and Reply   ----------
	
	public void setPartnerLink(PartnerLink pl){
		this.setPartnerReceive(pl);
		this.setPartnerReply(pl);
	}
	
	private void setPartnerReply(PartnerLink pl){
		this.reply.setPartnerLink(pl);
	}
	
	private void setPartnerReceive(PartnerLink pl){
		this.receive.setPartnerLink(pl);
	}
	
//-----------------------------------------------------------	
	
	public Receive getReceive() {
		return receive;
	}

	public void setReceive(Receive receive) {
		this.receive = receive;
	}

	public Reply getReply() {
		return reply;
	}

	public void setReply(Reply reply) {
		this.reply = reply;
	}
	
	
//---------   Generate BPEL of the Sequence  ---------------
	@Override
	public String toBPEL() {
		String output = "<" + sequenceTag + " name=\"" + this.name +"\">\n";
		output = output + this.receive.toBPEL();
		for(int i = 0; i < this.subNodes.size(); i++){
			Node n = this.subNodes.get(i);
			System.out.println(n.getName());
			output = output + n.toBPEL();
		}
		output = output + this.reply.toBPEL();
		output = output + "</" + sequenceTag + ">";
		return output;
	}

}
